<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>菜单列表</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <link rel="shortcut icon" href="/favicon.ico" type="image/x-icon" />
    <link rel="stylesheet" href="__ADMIN__/css/font.css">
    <link rel="stylesheet" href="__ADMIN__/css/xadmin.css">
    <script type="text/javascript" src="__ADMIN__/js/jquery.min.js"></script>
    <script type="text/javascript" src="__ADMIN__/lib/layui/layui.js" charset="utf-8"></script>
    <script type="text/javascript" src="__ADMIN__/js/xadmin.js"></script>
	<style type="text/css">
		.header span{background: #009688;margin-left: 10px;color: #ffffff;margin-top: -5px;}
		.header button{float: right;margin-top: -5px;}
		.header div{border-bottom: solid 2px #009688;margin-top: 8px;}
		.backs{margin: 5px 0;float: right;}
	</style>
</head>
<body style="padding:10px 0px;">
	<input type="hidden" id="pid" value="{$pid}">
	<div class="header">
		<span class="layui-btn layui-btn-sm" onclick="menu()">一级菜单列表</span>
		<button class="layui-btn layui-btn-sm" onclick="add()">添加</button>
		<div></div>
	</div>
	<?php if($pid > 0){?>
	<input type="button" class="layui-btn layui-btn-sm backs" value="返回上级菜单" onclick="backs({$backId})">
	<?php }?>
	<table class="layui-table">
		<thead>
			<tr>
				<th>ID</th>
				<th>排序</th>
				<th>menu_id</th>
				<th>pid</th>
				<th>菜单名称</th>		
				<th>控制器</th>
				<th>方法</th>
				<th>是否隐藏(0显示;1隐藏)</th>
				<th>状态(0正常;1禁用)</th>
				<th>操作</th>
			</tr>
		</thead>
		<tbody>
			{volist name="list" id="vo"}
			<tr>
				<td>{$vo.menu_id}</td>
				<td>{$vo.ord}</td>
				<td>{$vo.menu_id}</td>
				<td>{$vo.pid}</td>
				<td>{$vo.title}</td>
				<td>{$vo.controller}</td>
				<td>{$vo.method}</td>
				<td>{$vo.ishidden==1?'隐藏':'显示'}</td>
				<td>{$vo.status==1?'禁用':'正常'}</td>
				<td>
					<button class="layui-btn layui-btn-xs" onclick="childs({$vo['menu_id']})">子菜单</button>
					<button class="layui-btn layui-btn-warm layui-btn-xs" onclick="add({$vo['menu_id']})">编辑</button>
					<button class="layui-btn layui-btn-danger layui-btn-xs" onclick="del({$vo['menu_id']})">删除</button>
				</td>
			</tr>
			{/volist}
		</tbody>
	</table>
</body>
</html>
<script type="text/javascript">
	layui.use(['layer'],function(){
		layer = layui.layer;
		$ = layui.jquery;
	});

	// 添加
	function add(mid){
		var pid = $('#pid').val();
		layer.open({
			type:2,
			title:mid>0?'编辑菜单':'添加菜单',
			shade:0.3,
			area:['500px','600px'],
			content:'/admin.php/menu/add?mid=' + mid + '&pid=' + pid
		});
	}
	// 编辑
	function edit(mid){
		var pid = $('$pid').val();
		layer.open({
			type:2,
			title:mid>0?'编辑菜单':'添加菜单',
			shade:0.3,
			area:['500px','600px'],
			content:'/admin.php/Menu/add?mid=' + mid + '$pid=' + pid
		})
	}
	// 删除
	function del(mid){
		layer.confirm('确定要删除吗？',{
			icon:3,
			btn:['确定','取消']
		},function(){
			$.post('/admin.php/Menu/delete',{'mid':mid},function(res){
				console.log(res);
				if(res.code>0){
					layer.alert(res.msg,{'icon':2});
				}else{
					layer.msg(res.msg,{'icon':1});
					setTimeout(function(){window.location.reload();},1000);
				}
			},'json');
		});
	}

	// childs
	function childs(mid){
		window.location.href = '?pid=' + mid
	}

	// backs
	function backs(pid){
		window.location.href = '?pid=' + pid
	}

	// menu
	function menu(){
		window.location.href = '/admin.php/Menu/index'
	}
	// test
	function test(mid){
		$.ajax({
			type:'post',
			url:'/admin.php/Menu/delete',
			dataType:'json',
			data:{
				'mid':mid
			},
			success:function(data){
				console.log(data);
			}
		})
	}
</script>